/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RegistrationManager;

import java.sql.*;
import DBManager.DBConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;



/**
 *
 * @author Alex
 */



/**
 *
 * @author maconcon
 */
public class RegistrationManager {
     public boolean addUser(Registration newUser)
    {
        boolean result = false;
        

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            String password=newUser.getPassword();
          /*  
            
             MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(password.getBytes());
     
            byte byteData[] = md.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
             sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }
        password=sb.toString();
            */
            
            
            //Construct SQL Query
            PreparedStatement pstmt =
                conn.prepareStatement("call register (?,?,?,?,?,?,?,?,?,?,?,?,?);");

            //append values for the parameters
            int i=1;

              pstmt.setString(i++, newUser.getUsername());
              pstmt.setString(i++, newUser.getPassword());
              pstmt.setString(i++, newUser.getFirstname());
              pstmt.setString(i++, newUser.getMiddlename());
              pstmt.setString(i++, newUser.getLastname());
              pstmt.setString(i++, newUser.getAddress());
              pstmt.setString(i++, newUser.getCity());
              pstmt.setString(i++, newUser.getPostal());
              pstmt.setString(i++, newUser.getEmail());   
              pstmt.setString(i++, newUser.getCreditname());
              pstmt.setString(i++, newUser.getCreditnumber());
              pstmt.setString(i++, newUser.getExpdate());
              pstmt.setString(i++, newUser.getCredittype());
              


            //execute SQL statement
            pstmt.executeUpdate();
            result = true;
            
          

        }
        catch(SQLException ex){ex.printStackTrace();}

        return result; 
        
    }
     
     
}

 
     

